<?php

namespace app\admin\controller;

use think\Controller;
use think\Db;


class OcrArt extends Controller
{
    public function getOcrqueList()
    {

        $data = request()->post();
        $page = isset($data['page']) ? $data['page'] : 1;
        $limit = isset($data['limit']) ? $data['limit'] : 10;

        $map = [];
        $map['is_delete'] = '0';

        if ($data['status'] == 1) {
            $map['z_status'] = array("<>", 0);
        }

        if ($data['status'] == "0") {
            $map['z_status'] = array("=", $data['status']);
        }

        if ($data['task_id'] != "") {
            $map['task_id'] = array("=", $data['task_id']);
        }


        
        $count = Db::table('zstp_article')
            ->where($map)
            ->count();  

        $list = Db::table('zstp_article')
            ->where($map)
            ->page($page, $limit)
            ->order('create_time desc')
            ->select();

        return json(['code' => 200, 'message' => '获取成功', 'data' => $list, 'count' => $count]);

            
            

    }

    public function index()
    {
        $data = request()->post();
        $page = isset($data['page']) ? $data['page'] : 1;
        $limit = isset($data['limit']) ? $data['limit'] : 10;
        $length = $limit;
        //$page = 2;
        if (empty($data['page'])) {
            $page = 0;
        } else {
            $page = $data['page'] - 1;
        }
        $offset = $page * $length;
        $map = array();

        $map = [];
        $map['is_delete'] = '0';

        $map['ocr_status'] = array("<>", 0);

        if (!empty($data['dh'])) {
            $map['dh'] = array("=", $data['dh']);
        }

        if (!empty($data['content'])) {
            $map['content'] = ['like', '%' . $data['content'] . '%'];
        }

        if (!empty($data['bgqx'])) {
            $map['bgqx'] = array("=", $data['bgqx']);
        }


        if (!empty($data['mj'])) {
            $map['mj'] = array("=", $data['mj']);
        }

        if (!empty($data['lbh'])) {
            $map['lbh'] = array("=", $data['lbh']);
        }

        if (!empty($data['qzh'])) {
            $map['qzh'] = array("=", $data['qzh']);
        }

        if (!empty($data['sj'])) {
            $map['sj'] = array("=", $data['sj']);
        }

        if (!empty($data['tm'])) {
            $map['tm'] = array("=", $data['tm']);
        }

        if (!empty($data['wjbh'])) {
            $map['wjbh'] = array("=", $data['wjbh']);
        }

        if (!empty($data['wz'])) {
            $map['wz'] = array("=", $data['wz']);
        }

        if (!empty($data['ztc'])) {
            $map['ztc'] = array("=", $data['ztc']);
        }

        $count = Db::table('zstp_article')
            ->where($map)
            ->count();  

        $list = Db::table('zstp_article')
            ->where($map)
            ->page($page, $limit)
            ->order('create_time desc')
            ->select();

            return json(array(
                "code" => 200,
                "data" => array("resultList" => $list),
                "totalCount" => $count,
            ));

    }


    public function getDocById(){
        $data = request()->post();
        $id = isset($data['id']) ? $data['id'] : '';

        if (empty($id)) {
            return json(['code' => 400, 'message' => '参数错误']);
        }

        $doc = Db::table('zstp_article')
            ->where('id', $id)
            ->find();

            // var_dump($doc);

            $serverIp = config("kgFilePath");

            $monolayer = getMonolayerName($id);

            $file_path_df = $serverIp ."pdf/data/{$doc['id']}/{$monolayer}";
            $double_layer_pdf = $serverIp ."pdf/data/{$doc['id']}//{$doc['dh']}.pdf";
            $doc["single_layer_pdf"]= $file_path_df;
            $doc["double_layer_pdf"]= $double_layer_pdf;



        return json(['code' => 200, 'message' => '获取成功', 'data' => $doc]);
        
    }
        
}